package entities_testCase;

import java.util.ArrayList;

import junit.framework.TestCase;
import smallTools.SimpleTime;
import entities.Room;
import entities.Section;

public class RoomTest extends TestCase {

	private String roomId1;
	private int quota1;
	private Room room1;

	public void setUp() {
		roomId1 = "rm1";
		quota1 = 50;
		room1 = new Room(roomId1, quota1);
	}

	public void tearDown() {
		Room.clear();
		Section.clear();
	}

	public void test_insertTwice() {
		new Room(roomId1, quota1);
		assertEquals(1, Room.getNumOfRoom());
	}

	public void test_basicGettersAndSetters() {
		Room rm = Room.getRoomById(roomId1);
		assertEquals(roomId1, rm.getRoomId());

		assertEquals(1, Room.getNumOfRoom());
	}

	public void test_addSection_getRoomByQuota() {
		Section section1 = new Section("sectionId1", 60, 2, null);
		section1.setSectionStartTime(new SimpleTime("Mon", 11, 30));
		Section section2 = new Section("sectionId2", 60, 2, null);
		section2.setSectionStartTime(new SimpleTime("Mon", 9, 30));
		// for loop coverage
		assertEquals(0, room1.getRelatedSectionIds().length);
		room1.addSection("sectionId1");
		// for loop coverage
		assertEquals(1, room1.getRelatedSectionIds().length);
		room1.addSection("sectionId2");

		String[] allSectionIds = room1.getRelatedSectionIds();
		assertEquals(2, allSectionIds.length);
		assertEquals("sectionId1", allSectionIds[1]);
		assertEquals("sectionId2", allSectionIds[0]);
	}

	public void test_getRoomsByQuota() {
		ArrayList<Room> roomsWithQuota1 = Room.getRoomsByQuota(quota1);
		assertEquals(1, roomsWithQuota1.size());
		assertEquals(roomId1, roomsWithQuota1.get(0).getRoomId());
	}

	// for loop coverage
	public void test_getRoomsByQuotaForLoopCoverage() {
		ArrayList<Room> roomsWithQuota;
		roomsWithQuota = Room.getRoomsByQuota(quota1 + 10);
		assertEquals(0, roomsWithQuota.size());
		Room.clear();
		roomsWithQuota = Room.getRoomsByQuota(quota1);
		assertEquals(0, roomsWithQuota.size());
		new Room("LoopCoverage1", quota1);
		roomsWithQuota = Room.getRoomsByQuota(quota1);
		assertEquals(1, roomsWithQuota.size());
		new Room("LoopCoverage2", quota1);
		roomsWithQuota = Room.getRoomsByQuota(quota1);
		assertEquals(2, roomsWithQuota.size());
	}
}
